package com.visikard.asynctask;

import android.os.Handler;

import com.visikard.application.UIMessage;
import com.visikard.business.AccountBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.SendEmailResponse;
import com.visikard.utility.Utils;

public class ForgotPassTask extends BaseTask {

	public static final int POS_EMAIL = 0;

	public ForgotPassTask(Handler handler) {
		super(handler);
	}

	public ForgotPassTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {
		String email = (String) params[POS_EMAIL];

		// validation
		if (!Utils.isValidEmail(email)) {
			mUIHandler.sendEmptyMessage(UIMessage.MSG_IN_VALID_EMAIL);
			return null;
		}

		AccountBUS busObj = new AccountBUS();
		return busObj.forgotPass(email);
	}

	@Override
	protected boolean handleResult(Object result) {
		SendEmailResponse response = (SendEmailResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					mUIHandler.sendEmptyMessage(UIMessage.MSG_SEND_EMAIL_SUCCESS);
					return true;
				case SendEmailResponse.ERROR_EMAIL_NOT_EXISTS:
					mUIHandler.sendEmptyMessage(UIMessage.MSG_EMAIL_NOT_EXISTS);
					return true;
			}
		}
		return false;
	}

}
